//
//  UITextField+CycleLimit.h
//  CycleControlFunction
//
//  Created by ddy on 2018/11/26.
//  Copyright © 2018年 cycle. All rights reserved.
//  文本输入限制,placeholder颜色

#import <UIKit/UIKit.h>

typedef BOOL(^BNConditionBlock)(NSString *inputString);

NS_ASSUME_NONNULL_BEGIN

@interface UITextField (CycleLimit)

/**
 * 1.限制输入的字数(比如电话限制输入11位,密码限制输入6位等)
 */
- (void)cycle_limitInputNums:(NSInteger)num action:(void(^)(void))action;
/**
 * 2.限制条件
 */
- (void)cycle_limitCondition:(BNConditionBlock)condition action:(void(^)(void))action;
/**
 * 3.根据条件监听文字改变
 */
- (void)cycle_obserceValueWithCondition:(BNConditionBlock)condition action:(void(^)(void))action;
/**
 * 4.设置占位文字,占位文字颜色,占位文字字体
 */
- (void)cycle_setPlaceHolder:(NSString *)placeholder placeHolderColor:(UIColor *)color placeHolderFontSize:(UIFont *)font;


/*
 use:
 
 UITextField *testField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
 testField.center = self.view.center;
 testField.backgroundColor = [UIColor grayColor];
 [self.view addSubview:testField];
 
 __weak typeof(self) weakself = self;
 __weak typeof(testField) weaktext = testField;
 [testField limitCondition:^BOOL(NSString *inputStr){
 NSLog(@"~~~~limit --- %@",inputStr);
 return ![weaktext.text isEqualToString:@"11"];
 } action:^{
 NSLog(@"limit action");
 // [weakself dismissViewControllerAnimated:true completion:nil];
 }];
 
 [testField limitNums:2 action:^{
 NSLog(@"num limit action");
 //[weakself presentViewController:[ViewController new] animated:true completion:nil];
 }];
 
 [testField observeValueWithCondition:^BOOL(NSString *inputStr) {
 NSLog(@"observe~~~~~ %@---%@",inputStr,testField.text);
 return weaktext.text.length%2 == 1;
 } action:^{
 NSLog(@"vlaue is conformed");
 }];
 */

@end

NS_ASSUME_NONNULL_END
